package com.qianli.controller;

import com.qianli.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.qianli.service.impl"})
public class loginController {

    @Autowired
    AdminServiceImpl adminService;

    @RequestMapping(value = "/loguser")
    public Object login(@RequestParam  Map map, HttpServletRequest request){
        Map masp=new HashMap();
        if (map.get("name")!=null) {
           List<Map>  lu=adminService.selectUser(map);
           if (!lu.isEmpty()){
               HttpSession session = request.getSession();
               session.setAttribute("user", map.get("name").toString());
               masp.put("data","success");
           }else{
               masp.put("data","fail");
           }
        }else{
            masp.put("data","fail");
        }
        return masp;
    }
}
